<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            position: absolute;
            top: 120px;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
    <script>
        window.onload = function () {
            var btn = document.querySelector('button')
            var box = document.querySelector('div')
            var moveVal = 0;
            var timer = null;
            btn.onclick = function () {
                clearInterval(timer)
                timer = setInterval(() => {
                    moveVal += 3;
                    box.style.left = moveVal + "px"
                }, 30)
            }
        }
    </script>
</head>

<body>
    <button>点我</button>
    <div class="box"></div>
</body>

</html>